package cn.herlioner.service;

import java.util.ArrayList;
import java.util.List;

import cn.herlioner.dao.impl.CollegeDAOImpl;
import cn.herlioner.dao.impl.JudgeDAOImpl;
import cn.herlioner.dao.impl.Obj_TeaDAOImpl;
import cn.herlioner.dao.impl.ObjectDAOImpl;
import cn.herlioner.dao.impl.StudentDAOImpl;
import cn.herlioner.dao.impl.TeacherDAOImpl;
import cn.herlioner.pojo.CRUObject;
import cn.herlioner.pojo.College;
import cn.herlioner.pojo.Judge;
import cn.herlioner.pojo.Obj_Stu;
import cn.herlioner.pojo.Obj_Tea;
import cn.herlioner.pojo.TSObject;
import cn.herlioner.pojo.Teacher;

/**
 * 用以组合传给前端的课程信息
 * @author 谢鸿
 *
 */
public class CRUObjectService {
		Judge judge = new Judge();
		College college = new College();
		Obj_Tea obj_Tea = new Obj_Tea();
		Teacher teacher = new Teacher();
		
		JudgeDAOImpl judgeDAO = new JudgeDAOImpl();
		CollegeDAOImpl collegeDAO = new CollegeDAOImpl();
		TeacherDAOImpl teacherDAO = new TeacherDAOImpl();
		Obj_TeaDAOImpl obj_TeaDAO = new Obj_TeaDAOImpl();
		
		List<Obj_Tea> obj_Teas = obj_TeaDAO.list();
		List<Judge> judges = judgeDAO.list();
		


		public Judge getJudge() {
			return judge;
		}

		public void setJudge(Judge judge) {
			this.judge = judge;
		}

		public College getCollege() {
			return college;
		}

		public void setCollege(College college) {
			this.college = college;
		}

		public Obj_Tea getObj_Tea() {
			return obj_Tea;
		}

		public void setObj_Tea(Obj_Tea obj_Tea) {
			this.obj_Tea = obj_Tea;
		}

		public Teacher getTeacher() {
			return teacher;
		}

		public void setTeacher(Teacher teacher) {
			this.teacher = teacher;
		}

		public JudgeDAOImpl getJudgeDAO() {
			return judgeDAO;
		}

		public void setJudgeDAO(JudgeDAOImpl judgeDAO) {
			this.judgeDAO = judgeDAO;
		}

		public CollegeDAOImpl getCollegeDAO() {
			return collegeDAO;
		}

		public void setCollegeDAO(CollegeDAOImpl collegeDAO) {
			this.collegeDAO = collegeDAO;
		}

		public TeacherDAOImpl getTeacherDAO() {
			return teacherDAO;
		}

		public void setTeacherDAO(TeacherDAOImpl teacherDAO) {
			this.teacherDAO = teacherDAO;
		}

		public Obj_TeaDAOImpl getObj_TeaDAO() {
			return obj_TeaDAO;
		}

		public void setObj_TeaDAO(Obj_TeaDAOImpl obj_TeaDAO) {
			this.obj_TeaDAO = obj_TeaDAO;
		}

		public List<Obj_Tea> getObj_Teas() {
			return obj_Teas;
		}

		public void setObj_Teas(List<Obj_Tea> obj_Teas) {
			this.obj_Teas = obj_Teas;
		}

		
		public List<Judge> getJudges() {
			return judges;
		}

		public void setJudges(List<Judge> judges) {
			this.judges = judges;
		}

		public CRUObject setobject(TSObject tSObject,CRUObject cruObject){
			Long objnum = tSObject.getObjnum();
			Long clgnum = tSObject.getClgnum();
			Long teanum;
			
			Obj_Tea obj_Tea = obj_TeaDAO.getbyobjnum(objnum);
			
			if(obj_Tea==null){
				teanum = (long) 100001; 
			}else{
				teanum = obj_Tea.getTeanum();
			}
			
			//将三种查询优化成一句话
			Teacher teacher1 = teacherDAO.get(teanum);
			College college1 = collegeDAO.get(clgnum);
			
			//合成信息
			try {
				cruObject.set(tSObject, teacher1, college1);
			} catch (Exception e) {
				return null;
			}
			System.out.println("拼接时间");
			
			return cruObject;
		}
		
		/**
		 * 根据cruObject对象修改object对象
		 * @param cruObject
		 */
		public void update(CRUObject cruObject) {
			// TODO Auto-generated method stub
			
		}

		public CRUObject setobject(Obj_Tea obj_Tea2, CRUObject cruObject) {
			ObjectDAOImpl daoImpl = new ObjectDAOImpl();
			TeacherDAOImpl daoImpl2 = new TeacherDAOImpl();
			
			TSObject tsObject = daoImpl.get(obj_Tea2.getObjnum()).get(0);
			Teacher teacher = daoImpl2.get(obj_Tea2.getTeanum());
			//合成信息
			try {
				cruObject.set(tsObject,teacher);
			} catch (Exception e) {
				return null;
			}
			return cruObject;
		}

		public CRUObject setobjselct(Long objnum, CRUObject cruObject) {
			
			Obj_TeaDAOImpl obj_TeaDAOImpl = new Obj_TeaDAOImpl();
			Long teanum = obj_TeaDAOImpl.getbyobjnum(objnum).getTeanum();
			
			ObjectDAOImpl daoImpl = new ObjectDAOImpl();
			TeacherDAOImpl daoImpl2 = new TeacherDAOImpl();
			
			TSObject tsObject = daoImpl.get(objnum).get(0);
			Teacher teacher = daoImpl2.get(teanum);
			
			College college = collegeDAO.get(tsObject.getClgnum());
			//合成信息
			try {
				cruObject.set(teacher,tsObject,college);
			} catch (Exception e) {
				return null;
			}
			return cruObject;
		}


}
